package com.zhouyer.sqlSession;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLException;
import java.util.List;

public interface SqlSession {
    /**
     * 查询所有记录
     *
     * @param statementId sql对应标示
     * @param params      可变参数
     * @param <E>         集合中的实体类型
     * @return
     */
    <E> List<E> selectList(String statementId, Object... params) throws SQLException, IllegalAccessException, IntrospectionException, InstantiationException, NoSuchFieldException, InvocationTargetException, ClassNotFoundException;

    /**
     * 查询一条记录
     *
     * @param statementId sql对应标示
     * @param params      参数
     * @param <T>         单个实体对象
     * @return
     */
    <T> T selectOne(String statementId, Object... params) throws SQLException, IllegalAccessException, IntrospectionException, InstantiationException, ClassNotFoundException, InvocationTargetException, NoSuchFieldException;

    /**
     * 插入记录
     *
     * @param statementId
     * @param params
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     * @throws IllegalAccessException
     * @throws NoSuchFieldException
     */
    int insert(String statementId, Object... params) throws ClassNotFoundException, SQLException, IllegalAccessException, NoSuchFieldException;

    /**
     * 更新记录
     *
     * @param statementId sql标示
     * @param params      更新的记录
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     * @throws IllegalAccessException
     * @throws NoSuchFieldException
     */
    int update(String statementId, Object... params) throws ClassNotFoundException, SQLException, IllegalAccessException, NoSuchFieldException;

    /**
     * 删除记录
     *
     * @param statementId sql标示
     * @param params      参数
     * @return
     * @throws ClassNotFoundException
     * @throws SQLException
     * @throws IllegalAccessException
     * @throws NoSuchFieldException
     */
    int delete(String statementId, Object... params) throws ClassNotFoundException, SQLException, IllegalAccessException, NoSuchFieldException;

    /**
     * 根据传入的类获取代理对象
     *
     * @param mapperClass
     * @param <T>
     * @return
     */
    <T> T getMapper(Class<?> mapperClass);
}
